package com.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.common.R;
import com.demo.domain.Orders;
import com.demo.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags="订单详情")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    @ApiOperation(value = "新增订单")
    public R<String> submit(@RequestBody Orders orders) {
        log.info("前端传来的orders为 {}", orders.toString());
        return ordersService.submit(orders);
    }

    @GetMapping("/userPage")
    @ApiOperation(value = "分页查询订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页记录数",required = true),
    })
    public R<Page> userPage(int page, int pageSize) {
        log.info("前端传来的参数page为 {} pageSize为 {}", page, pageSize);
        Page<Orders> pageInfo = new Page<>(page,pageSize);

        return ordersService.userPage(pageInfo);
    }


}
